package com.sense.kukoo.biz_me.adapter.provider

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.sense.kukoo.biz_me.adapter.MeChannelAdapter
import com.sense.kukoo.common.R
import com.sense.kukoo.common.repo.biz.ChannelContentBean
import com.sense.kukoo.common.repo.http.bean.UserInfoBean
import com.sense.kukoo.common.utils.ApplicationContext
import com.sense.kukoo.common.wiget.adapter.provider.MultiItemProvider
import com.sense.kukoo.common.wiget.adapter.viewholder.BaseViewHolder
import com.sense.kukoo.lib_picture.config.GlideConfig
import com.sense.kukoo.lib_picture.loader.Monet

class MeChannelTitleItemProvider(
    val listener: MeChannelAdapter.IndexContentEventListener
): MultiItemProvider<ChannelContentBean>() {

    override fun getItemType(): Int = ChannelContentBean.TYPE_TITLE

    override fun getItemLayoutId(): Int = R.layout.common_item_channel_title

    override fun onBindViewHolder(viewHolder: BaseViewHolder, item: ChannelContentBean) {
        val data: UserInfoBean = item.user!!
        //
        val iv_me_header_icon = viewHolder.getView(R.id.iv_me_header_icon) as ImageView
        iv_me_header_icon.setOnClickListener {
            listener.onUserIconClick(data)
        }
        Monet.get(iv_me_header_icon.context)
            .load<GlideConfig>(data.getIconUrl())
            .placeholder(com.sense.kukoo.common_design.R.drawable.design_icon_avatar_default)
            .circleCrop()
            .into(iv_me_header_icon)
        //
        val tv_me_channel = viewHolder.getView(R.id.tv_me_channel) as TextView
        tv_me_channel.text = data.getName()
        tv_me_channel.setOnClickListener {
            listener.onUserChannelClick(data)
        }
        //
        val tv_me_id = viewHolder.getView(R.id.tv_me_id) as TextView
        tv_me_id.text = ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.num_id, data.id)
        tv_me_id.setOnClickListener {
            listener.onUserIdClick(data)
        }
        //
        val tv_me_followers = viewHolder.getView(R.id.tv_me_followers) as TextView
        tv_me_followers.text = "${data.fansNum}"
        //
        val tv_me_following = viewHolder.getView(R.id.tv_me_following) as TextView
        tv_me_following.text = "${data.subscriptionNum}"
        //
        val tv_me_likes = viewHolder.getView(R.id.tv_me_likes) as TextView
        tv_me_likes.text = "${data.likeNum}"
        //
        viewHolder.getView(R.id.ll_btn_followers).setOnClickListener {
            listener.onBtnFollowersClick(data)
        }
        //
        viewHolder.getView(R.id.ll_btn_following).setOnClickListener {
            listener.onBtnFollowingsClick(data)
        }
        //
        val tv_me_listened = viewHolder.getView(R.id.tv_me_listened) as TextView
        var min = data.listenedTimes / 60
        val hour = min / 60
        if(hour > 0){
            min = min % 60
            tv_me_listened.text = ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.time_formate_min_and_hour, hour, min)
        } else {
            tv_me_listened.text = ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.time_formate_min, min)
        }
        //Me页面没有follow按钮
        val tv_btn_follow = viewHolder.getView(R.id.tv_btn_follow) as TextView
        tv_btn_follow.visibility = View.GONE
    }
}